<!DOCTYPE HTML>
<html lang="en" >
    <!-- Start book 6节课入门Flask框架web开发 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>过滤器 | 6节课入门Flask框架web开发</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../chapter2/hong.html" />
    
    
    <link rel="prev" href="../chapter2/jinja2mo-ban-yin-qing.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="2.2"
        data-chapter-title="过滤器"
        data-filepath="chapter2/guo-lv-qi.md"
        data-basepath=".."
        data-revision="Sun Jan 28 2018 01:59:46 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Flask快速入门课程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="chapter1.html">
            
                
                    <a href="../chapter1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        Flask基础
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="chapter1/flaskjian-jie.html">
            
                
                    <a href="../chapter1/flaskjian-jie.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        为什么要使用WEB框架
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="chapter1/flaskyu-django-dui-bi.html">
            
                
                    <a href="../chapter1/flaskyu-django-dui-bi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        Flask简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="chapter1/flask-an-zhuang-huan-jing.html">
            
                
                    <a href="../chapter1/flask-an-zhuang-huan-jing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        Flask 安装环境
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="chapter1/requirements-wen-jian.html">
            
                
                    <a href="../chapter1/requirements-wen-jian.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        requirements 文件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="chapter1/hello-worldcheng-xu.html">
            
                
                    <a href="../chapter1/hello-worldcheng-xu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        Hello World程序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="chapter1/lu-you-de-ge-zhong-ding-yi-fang-shi.html">
            
                
                    <a href="../chapter1/lu-you-de-ge-zhong-ding-yi-fang-shi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        路由定义的基本方式
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="chapter2.html">
            
                
                    <a href="../chapter2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        模板
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="chapter2/jinja2mo-ban-yin-qing.html">
            
                
                    <a href="../chapter2/jinja2mo-ban-yin-qing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        Jinja2模板引擎
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.2" data-path="chapter2/guo-lv-qi.html">
            
                
                    <a href="../chapter2/guo-lv-qi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        过滤器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="chapter2/hong.html">
            
                
                    <a href="../chapter2/hong.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        Flask-WTF表单
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="chapter3.html">
            
                
                    <a href="../chapter3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        数据库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="chapter3/shu-ju-ku-de-she-zhi.html">
            
                
                    <a href="../chapter3/shu-ju-ku-de-she-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Flask中使用数据库
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="chapter3/shu-ju-ku-ji-ben-cao-zuo.html">
            
                
                    <a href="../chapter3/shu-ju-ku-ji-ben-cao-zuo.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        数据库基本操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="chapter3/zong-he-an-4f8b-tu-shu-guan-li.html">
            
                
                    <a href="../chapter3/zong-he-an-4f8b-tu-shu-guan-li.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        综合案例-图书管理
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="chapter3/zong-he-an-4f8b-tu-shu-guan-li/ding-yi-mo-xing.html">
            
                
                    <a href="../chapter3/zong-he-an-4f8b-tu-shu-guan-li/ding-yi-mo-xing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                        定义模型&amp;创建表&amp;数据添加
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="chapter3/zong-he-an-4f8b-tu-shu-guan-li/shu-ju-xian-793a26-biao-dan-tian-jia.html">
            
                
                    <a href="../chapter3/zong-he-an-4f8b-tu-shu-guan-li/shu-ju-xian-793a26-biao-dan-tian-jia.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.2.</b>
                        
                        数据显示&amp;表单添加
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="chapter3/zong-he-an-4f8b-tu-shu-guan-li/biao-dan-yan-zheng.html">
            
                
                    <a href="../chapter3/zong-he-an-4f8b-tu-shu-guan-li/biao-dan-yan-zheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.3.</b>
                        
                        添加数据的表单验证
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.4" data-path="chapter3/zong-he-an-4f8b-tu-shu-guan-li/shan-chu-shu-ju.html">
            
                
                    <a href="../chapter3/zong-he-an-4f8b-tu-shu-guan-li/shan-chu-shu-ju.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.4.</b>
                        
                        删除数据
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >6节课入门Flask框架web开发</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x8FC7;&#x6EE4;&#x5668;">&#x8FC7;&#x6EE4;&#x5668;</h1>
<p>&#x8FC7;&#x6EE4;&#x5668;&#x7684;&#x672C;&#x8D28;&#x5C31;&#x662F;&#x51FD;&#x6570;&#x3002;&#x6709;&#x65F6;&#x5019;&#x6211;&#x4EEC;&#x4E0D;&#x4EC5;&#x4EC5;&#x53EA;&#x662F;&#x9700;&#x8981;&#x8F93;&#x51FA;&#x53D8;&#x91CF;&#x7684;&#x503C;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x53D8;&#x91CF;&#x7684;&#x663E;&#x793A;&#xFF0C;&#x751A;&#x81F3;&#x683C;&#x5F0F;&#x5316;&#x3001;&#x8FD0;&#x7B97;&#x7B49;&#x7B49;&#xFF0C;&#x800C;&#x5728;&#x6A21;&#x677F;&#x4E2D;&#x662F;&#x4E0D;&#x80FD;&#x76F4;&#x63A5;&#x8C03;&#x7528; Python &#x4E2D;&#x7684;&#x67D0;&#x4E9B;&#x65B9;&#x6CD5;&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x5C31;&#x7528;&#x5230;&#x4E86;&#x8FC7;&#x6EE4;&#x5668;&#x3002; </p>
<p>&#x4F7F;&#x7528;&#x65B9;&#x5F0F;&#xFF1A;</p>
<ul>
<li>&#x8FC7;&#x6EE4;&#x5668;&#x7684;&#x4F7F;&#x7528;&#x65B9;&#x5F0F;&#x4E3A;&#xFF1A;&#x53D8;&#x91CF;&#x540D; | &#x8FC7;&#x6EE4;&#x5668;&#x3002; </li>
</ul>
<pre><code class="lang-python">{{variable | filter_name(*args)}}
</code></pre>
<ul>
<li>&#x5982;&#x679C;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x53C2;&#x6570;&#x4F20;&#x7ED9;&#x8FC7;&#x6EE4;&#x5668;,&#x5219;&#x53EF;&#x4EE5;&#x628A;&#x62EC;&#x53F7;&#x7701;&#x7565;&#x6389;</li>
</ul>
<pre><code class="lang-python">{{variable | filter_name}}
</code></pre>
<ul>
<li>&#x5982;&#xFF1A;``&#xFF0C;&#x8FD9;&#x4E2A;&#x8FC7;&#x6EE4;&#x5668;&#x7684;&#x4F5C;&#x7528;&#xFF1A;&#x628A;&#x53D8;&#x91CF;variable &#x7684;&#x503C;&#x7684;&#x9996;&#x5B57;&#x6BCD;&#x8F6C;&#x6362;&#x4E3A;&#x5927;&#x5199;&#xFF0C;&#x5176;&#x4ED6;&#x5B57;&#x6BCD;&#x8F6C;&#x6362;&#x4E3A;&#x5C0F;&#x5199;</li>
</ul>
<h2 id="&#x94FE;&#x5F0F;&#x8C03;&#x7528;">&#x94FE;&#x5F0F;&#x8C03;&#x7528;</h2>
<p>&#x5728; jinja2 &#x4E2D;&#xFF0C;&#x8FC7;&#x6EE4;&#x5668;&#x662F;&#x53EF;&#x4EE5;&#x652F;&#x6301;&#x94FE;&#x5F0F;&#x8C03;&#x7528;&#x7684;&#xFF0C;&#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-python">{{ <span class="hljs-string">&quot;hello world&quot;</span> | reverse | upper }}
</code></pre>
<h2 id="&#x5E38;&#x89C1;&#x5185;&#x5EFA;&#x8FC7;&#x6EE4;&#x5668;">&#x5E38;&#x89C1;&#x5185;&#x5EFA;&#x8FC7;&#x6EE4;&#x5668;</h2>
<h3 id="&#x5B57;&#x7B26;&#x4E32;&#x64CD;&#x4F5C;">&#x5B57;&#x7B26;&#x4E32;&#x64CD;&#x4F5C;</h3>
<ul>
<li>safe&#xFF1A;&#x7981;&#x7528;&#x8F6C;&#x4E49;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ &apos;&lt;em&gt;hello&lt;/em&gt;&apos; | safe }}&lt;/p&gt;
</code></pre>
<ul>
<li>capitalize&#xFF1A;&#x628A;&#x53D8;&#x91CF;&#x503C;&#x7684;&#x9996;&#x5B57;&#x6BCD;&#x8F6C;&#x6210;&#x5927;&#x5199;&#xFF0C;&#x5176;&#x4F59;&#x5B57;&#x6BCD;&#x8F6C;&#x5C0F;&#x5199;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ &apos;hello&apos; | capitalize }}&lt;/p&gt;
</code></pre>
<ul>
<li>lower&#xFF1A;&#x628A;&#x503C;&#x8F6C;&#x6210;&#x5C0F;&#x5199;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ &apos;HELLO&apos; | lower }}&lt;/p&gt;
</code></pre>
<ul>
<li>upper&#xFF1A;&#x628A;&#x503C;&#x8F6C;&#x6210;&#x5927;&#x5199;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ &apos;hello&apos; | upper }}&lt;/p&gt;
</code></pre>
<ul>
<li>title&#xFF1A;&#x628A;&#x503C;&#x4E2D;&#x7684;&#x6BCF;&#x4E2A;&#x5355;&#x8BCD;&#x7684;&#x9996;&#x5B57;&#x6BCD;&#x90FD;&#x8F6C;&#x6210;&#x5927;&#x5199;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ &apos;hello&apos; | title }}&lt;/p&gt;
</code></pre>
<ul>
<li>reverse&#xFF1A;&#x5B57;&#x7B26;&#x4E32;&#x53CD;&#x8F6C;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ &apos;olleh&apos; | reverse }}&lt;/p&gt;
</code></pre>
<ul>
<li>format&#xFF1A;&#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ &apos;%s is %d&apos; | format(&apos;name&apos;,17) }}&lt;/p&gt;
</code></pre>
<ul>
<li>striptags&#xFF1A;&#x6E32;&#x67D3;&#x4E4B;&#x524D;&#x628A;&#x503C;&#x4E2D;&#x6240;&#x6709;&#x7684;HTML&#x6807;&#x7B7E;&#x90FD;&#x5220;&#x6389;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ &apos;&lt;em&gt;hello&lt;/em&gt;&apos; | striptags }}&lt;/p&gt;
</code></pre>
<ul>
<li>truncate: &#x5B57;&#x7B26;&#x4E32;&#x622A;&#x65AD;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ &apos;hello every one&apos; | truncate(9)}}&lt;/p&gt;
</code></pre>
<h3 id="&#x5217;&#x8868;&#x64CD;&#x4F5C;">&#x5217;&#x8868;&#x64CD;&#x4F5C;</h3>
<ul>
<li>first&#xFF1A;&#x53D6;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ [1,2,3,4,5,6] | first }}&lt;/p&gt;
</code></pre>
<ul>
<li>last&#xFF1A;&#x53D6;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ [1,2,3,4,5,6] | last }}&lt;/p&gt;
</code></pre>
<ul>
<li>length&#xFF1A;&#x83B7;&#x53D6;&#x5217;&#x8868;&#x957F;&#x5EA6;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ [1,2,3,4,5,6] | length }}&lt;/p&gt;
</code></pre>
<ul>
<li>sum&#xFF1A;&#x5217;&#x8868;&#x6C42;&#x548C;</li>
</ul>
<pre><code class="lang-python">&lt;p&gt;{{ [1,2,3,4,5,6] | sum }}&lt;/p&gt;
</code></pre>
<ul>
<li>sort&#xFF1A;&#x5217;&#x8868;&#x6392;&#x5E8F;</li>
</ul>
<pre><code>&lt;p&gt;{{ [6,2,3,1,5,4] | sort }}&lt;/p&gt;
</code></pre><h3 id="&#x8BED;&#x53E5;&#x5757;&#x8FC7;&#x6EE4;">&#x8BED;&#x53E5;&#x5757;&#x8FC7;&#x6EE4;</h3>
<pre><code class="lang-pyhton">{% filter upper %}
    &#x4E00;&#x5927;&#x5806;&#x6587;&#x5B57;
{% endfilter %}
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../chapter2/jinja2mo-ban-yin-qing.html" class="navigation navigation-prev " aria-label="Previous page: Jinja2模板引擎"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../chapter2/hong.html" class="navigation navigation-next " aria-label="Next page: Flask-WTF表单"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"toggle-chapters":{},"splitter":{},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book 6节课入门Flask框架web开发 -->
</html>
